package com.aier.school.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.common.ClassesFinalPageSize;
import com.aier.classes.entity.Classes;
import com.aier.classes.entity.InviteTeacher;
import com.aier.classes.service.IClassService;
import com.aier.common.dao.ICommonDAO;
import com.aier.school.common.SchoolFinalPageSize;
import com.aier.school.entity.SchoolGrade;
import com.aier.school.entity.SchoolTeacher;
import com.aier.school.service.ISchoolService;
import com.aier.school.service.ISchoolTeacherService;

@Scope("prototype")
@Component("schoolTeacherManageAction")
public class SchoolTeacherManageAction extends SchoolBaseAction{

    /**
     * 学校管理-教师管理
     */
    private static final long serialVersionUID = 1L;

    @Resource(name = "schoolService")
    private ISchoolService schoolService;    
    @Resource(name = "schoolTeacherService")
    private ISchoolTeacherService schoolTeacherService;        
    @Resource(name = "classService")
    private IClassService classService;        
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息
        
    private Integer sid;        //学校id
    private List<String> tnameAccountList;        //教师名字账号列表
    private List<SchoolGrade> schoolGradeList;    //职务列表    
    private List<Classes> classList;            //班级列表    
    private List<SchoolTeacher> schoolTeacherList;        //学校教师列表                 
    private Long tid;            //教师id
    private Long gid;            //职务id
    private String account;        //教师账号
    private Short isadmin_school;                //是否学校管理员
    private SchoolTeacher schoolTeacher;        //学校教师
    private String cidList;                        //班级id(以,分隔)
    private String cidList_isadmin;                //管理班级id(以,分隔)
    
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数
    
    private List<InviteTeacher> inviteTeacherList;    //教师邀请记录列表
    private String inviteTea_message;                 //教师邀请的字符串 "cid,tname,gid,phone@XXX"
    
    @Override
    public String execute(){
        tnameAccountList = schoolTeacherService.searchTNameAndAccountBySid(sid);
        tnameAccountList.add(0, "所有教师");
        schoolGradeList = schoolService.searchSchoolGradeList(sid);
        classList = classService.searchClassList(sid);
        
        return SUCCESS;
    }
    
    /**
     * 查询学校教师
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchSchoolTeacherList(){
        s = 1;    
        Map<String,Object> map = schoolTeacherService.searchSchoolTeacherList(page, 
                SchoolFinalPageSize.CLASSES_MAINTAIN_LIST_PAGESIZE, sid,account,gid);
        if(null==map){
            s = 0;
        }
        schoolTeacherList = (List<SchoolTeacher>) map.get(ICommonDAO.OBJ_LIST);
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        return SUCCESS;
    }
    
    /**
     * APP端查询学校教师
     * @return
     */
    public String searchSchoolTeacherListApp(){
    	Map<String,Object> map = schoolTeacherService.searchSchoolTeacherList(page, page_size, sid,account,gid);
        if(null==map){
            s = 0;
        }
        schoolTeacherList = (List<SchoolTeacher>) map.get(ICommonDAO.OBJ_LIST);
        s=1;
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
    	return SUCCESS;
    	}
    
    /**
     * 获取要管理的教师
     */
    public String showSchoolTeacher(){
        schoolTeacher = schoolTeacherService.searchSchoolTeacherById(tid);
        return SUCCESS;
    }
    
    /**
     * 删除教师
     * @return
     */
    public String deleteSchoolTeacher(){
        s = schoolTeacherService.deleteSchoolTeacher(tid);
        return SUCCESS;
    }
    
    /**
     * 修改教师学校管理权限
     */
    public String updateSchoolTeacherAdmin(){
        s = schoolTeacherService.updateSchoolTeacherState(tid, isadmin_school);
        return SUCCESS;
    }

    /**
     * 修改教师--职务,班级,管理班级
     */
    public String updateSchoolTeacherManager(){
        s = schoolTeacherService.updateSchoolTeacherManager(tid, gid,cidList,cidList_isadmin);
        
        return SUCCESS;
    }
    
    /**
     * 查询邀请教师记录
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchInviteTeacherList(){
        s = 1;
        Map<String,Object> map = schoolTeacherService.searchInviteTeacherList(page, ClassesFinalPageSize.TEACHER_INVITE_LIST_PAGESIZE, sid);
        if(null==map){
            s = 0;
        }
        inviteTeacherList = (List<InviteTeacher>) map.get(ICommonDAO.OBJ_LIST);
        if (null == inviteTeacherList) {
            s = 0;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        return SUCCESS;
    }
    
    /**
     * 添加教师邀请
     * @return
     */
    public String addTeacherInvite(){
        s = schoolTeacherService.insertTeacherList(sid, tid,inviteTea_message);
        return SUCCESS;
    }
    
    
    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public void setPage_count(int page_count) {
        this.page_count = page_count;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<SchoolGrade> getSchoolGradeList() {
        return schoolGradeList;
    }

    public List<Classes> getClassList() {
        return classList;
    }

    public List<SchoolTeacher> getSchoolTeacherList() {
        return schoolTeacherList;
    }

    public SchoolTeacher getSchoolTeacher() {
        return schoolTeacher;
    }

    public void setSchoolService(ISchoolService schoolService) {
        this.schoolService = schoolService;
    }

    public void setSchoolTeacherService(ISchoolTeacherService schoolTeacherService) {
        this.schoolTeacherService = schoolTeacherService;
    }

    public void setClassService(IClassService classService) {
        this.classService = classService;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public void setGid(Long gid) {
        this.gid = gid;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public void setIsadmin_school(Short isadmin_school) {
        this.isadmin_school = isadmin_school;
    }

    public void setCidList(String cidList) {
        this.cidList = cidList;
    }

    public void setCidList_isadmin(String cidList_isadmin) {
        this.cidList_isadmin = cidList_isadmin;
    }

    public List<String> getTnameAccountList() {
        return tnameAccountList;
    }

    public Integer getSid() {
        return sid;
    }

    public List<InviteTeacher> getInviteTeacherList() {
        return inviteTeacherList;
    }

    public void setInviteTea_message(String inviteTea_message) {
        this.inviteTea_message = inviteTea_message;
    }

    public Long getTid() {
        return tid;
    } 
}